function install(Vue, dict) {
  Vue.prototype.$d = function (key, value) {
    if (value == null || !dict[key.toUpperCase()]) return value
    return dict[key.toUpperCase()][value] || value
  }
  Vue.prototype.$dict = function (key) {
    if (!key) return {}
    return dict[key.toUpperCase()] || {}
  }
  Vue.prototype.$opts = function (dictName, keyList) {
    if (!dictName) return []
    if (!Array.isArray(keyList)) keyList = null
    const dict = this.$dict(dictName)
    return Object.keys(dict)
      .filter((item) => !keyList || keyList.includes(item))
      .map((key) => ({ label: dict[key], value: key }))
  }
}

class AzDict {}

AzDict.install = install

if (window && window.Vue) {
  window.Vue.use(AzDict)
}

export default AzDict
